<template>
  <div class="jumpcart" v-show="isShow">
    <div class="mask" @click.stop="close"></div>
    <div class="content-warp">
      <div class="image-header">
        <img :src="data.images?data.images[0].show_image:''">
      </div>
      <div class="title">{{data.product_name}}</div>
      <div class="extact">
        <div class="left">
          <div class="price">
            <span class="sale">{{data.price | formatMoney}}</span>
            <span class="del" v-show="data.original_price">{{data.original_price | formatMoney}}</span>
          </div>
        </div>
        <div class="right">
          <Cartcontrol :productData="data" />
          <!--<div class="contact" @click="contact">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-kefu"></use>
            </svg>
            <span class="text">联系客服</span>
          </div>-->
          <!--<div @click="addCart({productData: data, type: 1})" class="btn btn-primary">加入购物车</div>-->
        </div>
      </div>
      <div class="describe" v-if="data.content">
        {{data.content}}
      </div>
    </div>
  </div>
</template>

<script>
import { formatMoney } from '@/utils'
import { mapActions } from 'vuex'
import Cartcontrol from './cartcontrol'
export default {
  data() {
    return {
      isShow: false,
      isAddCart: false
    }
  },
  props: {
    data: null,
    show: false
  },
  methods: {
    ...mapActions([
      'addToCart'
    ]),
    contact() {
      /* eslint-disable */
      WeixinJSBridge.call('closeWindow')
    },
    close() {
      this.isShow = false
      this.$emit('close', true);
    },
    open() {
      this.isShow = true
    },
    addCart(data) {
      this.$layer.toast({
        content: '添加购物车成功!'
      })
      this.addToCart(data)
    }
  },
  filters: {
    formatMoney(number) {
      return formatMoney(number, '￥')
    }
  },
  components: {
    Cartcontrol
  }
}
</script>

<style lang="scss" scoped>
@import '../assets/styles/config';
.jumpcart {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: px2rem(45px);
  // bottom: 0;
  pointer-events: auto;
  z-index: 999;
  overflow: hidden;
  .mask {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    filter: blur(20px);
    background-color: rgba(0, 0, 0, 0.7);
  }
}

.content-warp {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 90%;
  padding: px2rem(10px);
  margin: auto;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: px2rem(6px);
  .image-header {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 66.7%;
    img {
      position: absolute;
      top: 0;
      left: 15%;
      width: px2rem(200px);
      height: px2rem(200px);
    }
  }
  .extact{
    display: flex;
    justify-content: space-between;
    align-items: center;
    .right{
      width: px2rem(128px);
      text-align: right;
    }
  }
  .describe{
    border-top: px2rem(1px) solid $gray;
    margin-top: px2rem(10px);
    padding-top: px2rem(10px);
    font-size:  px2rem(14px);
    line-height: 1.5;
    color: $dark;
  }
  .title {
    padding-top: px2rem(10px);
    font-size: px2rem(16px);
    height: px2rem(20px);
    margin-bottom: px2rem(10px);
    line-height: px2rem(20px);
    overflow: hidden;
  }
  .price {
    flex: 1;
    align-items: center;
  }
  .sale {
    font-size: px2rem(18px);
    color: $red;
    margin-right: px2rem(8px);
  }
  .del {
    color: $dark;
    font-size: px2rem(14px);
    text-decoration: line-through;
  }
  .contact {
    font-size: px2rem(12px);
    color: $dark;
  }

  .btn-primary{
    display: inline-block;
    height: px2rem(16px);
    margin-top: px2rem(12px);
    padding: px2rem(4px) px2rem(12px);
    border-radius: px2rem(4px);
    line-height: px2rem(16px);
    color: $white;
    font-size: px2rem(12px);
    border: px2rem(1px) solid darken($primary, 5%);
    background-color: $primary;
  }
}
</style>
